package com.ljfiction.book.activitys;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.androidkun.xtablayout.XTabLayout;
import com.ljfiction.book.R;
import com.ljfiction.book.adapter.IndentDetailAdapter;
import com.ljfiction.book.fragment.MydanmuFragment;
import com.ljfiction.book.fragment.MyshupingFragment;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class MyshupingActivity extends BaseActivity {

    @BindView(R.id.myshupingxtayble)
    XTabLayout myshupingxtayble;
    @BindView(R.id.myshupingviewpager)
    ViewPager myshupingviewpager;
    @BindView(R.id.back_myshuping)
    ImageView backMyshuping;

    private MyshupingFragment myshupingframent;
    private MydanmuFragment mydanmuFragment;
    private int type = 0;//0是从我的页面跳转过来，1是从他的主页跳到书评，2是从他的主页跳到段评；
    private ArrayList<Fragment> fragments = new ArrayList<>();
    private String tabTitles[] = new String[]{"书评", "吐槽"};
    private String userId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myshuping);
        ButterKnife.bind(this);
        type = getIntent().getIntExtra("type", 0);
        userId=getIntent().getStringExtra("userId");
        intview();
    }

    private void intview() {
        myshupingframent = MyshupingFragment.newInstance(type,userId);
        mydanmuFragment = MydanmuFragment.newInstance(type,userId);
        fragments.add(myshupingframent);
        fragments.add(mydanmuFragment);
        IndentDetailAdapter adapter = new IndentDetailAdapter(getSupportFragmentManager(), tabTitles, fragments);
        myshupingviewpager.setAdapter(adapter);
        myshupingviewpager.setOverScrollMode(View.OVER_SCROLL_NEVER);
        myshupingxtayble.setupWithViewPager(myshupingviewpager);
        if (type == 2) {
            myshupingviewpager.setCurrentItem(2);
        }


    }

    @OnClick(R.id.back_myshuping)
    public void onViewClicked() {
        goBack();
    }
}
